/**
 * Copyright [2019] [LiBo/Alex of copyright liboware@gmail.com ]
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.hyts.infodb.user.config;

import com.hyts.infodb.user.web.UserDataInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

/**
 * @project-name:infodb
 * @package-name:com.hyts.infodb.user
 * @author:LiBo/Alex
 * @create-date:2020-02-21 13:07
 * @copyright:libo-alex4java
 * @email:liboware@gmail.com
 * @description:
 */
@Configuration
public class UserRouteConfiguration extends WebMvcConfigurerAdapter {


    @Autowired
    UserDataInterceptor userDataInterceptor;


    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("swagger-ui.html")
                .addResourceLocations("classpath:/META-INF/resources/");
        registry.addResourceHandler("/webjars/**")
                .addResourceLocations("classpath:/META-INF/resources/webjars/");
    }

    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/").setViewName("switch");
        registry.addViewController("").setViewName("switch");
        registry.addViewController("/signin").setViewName("login");
        registry.addViewController("/findPwd").setViewName("findPwd");
        registry.addViewController("/changeInfo").setViewName("user/changeInfo");
        registry.addViewController("/changePwd").setViewName("user/changePwd");
    }


    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(userDataInterceptor).addPathPatterns("/index");
        registry.addInterceptor(userDataInterceptor).addPathPatterns("/main");
        registry.addInterceptor(userDataInterceptor).addPathPatterns("/top");
    }
}
